int main()
{
//通過(guò)IP端口創(chuàng)建協(xié)議
auto protocol = techlego::create_binary_protocol(L"localhost", 5252);
//通過(guò)協(xié)議創(chuàng)建客戶端
auto client = techlego::h_scan3d_client::make_shared(protocol);
//坐標(biāo)系1下的點(diǎn)坐標(biāo)
std::array<techlego::pos3f, 4>points1 = {
{ {-65.4562 ,-54.4644,378.7092},
{-65.3003 ,-54.4709 ,378.7567},
{-15.7148 ,-14.9020,380.3256 },
{-65.2903 ,- 54.4111 ,378.7333} } };
//坐標(biāo)系2下的點(diǎn)坐標(biāo)
std::array<techlego::pos3f, 4>points2 = {};
// 構(gòu)建繞Z軸旋轉(zhuǎn)45度的旋轉(zhuǎn)矩陣
Eigen::AngleAxisd angle_axis(M_PI / 4, Eigen::Vector3d(0, 0, 1));
Eigen::Matrix3d m = angle_axis.toRotationMatrix();
// 構(gòu)建平移向量
Eigen::Vector3d translate_vector(1, 3, 4);
// 對(duì)坐標(biāo)系1中的點(diǎn)應(yīng)用之前構(gòu)建的旋轉(zhuǎn)矩陣和平移向量,得到坐標(biāo)系2下的該點(diǎn)
for (int i = 0; i < points1.size(); i++)
{
// 用變換矩陣對(duì)坐標(biāo)進(jìn)行變換
// 點(diǎn)在坐標(biāo)系1下坐標(biāo)
Eigen::Vector3d point(points1[i].m_x, points1[i].m_y, points1[i].m_z);
// 變換,相當(dāng)于【旋轉(zhuǎn)矩陣*坐標(biāo)+平移向量】
Eigen::Vector3d point_after_trans = m * point + translate_vector;
std::cout << "變換后的坐標(biāo)為:" << std::endl << point_after_trans.transpose() << std::endl;
points2[i].m_x = point_after_trans(0);
points2[i].m_y = point_after_trans(1);
points2[i].m_z = point_after_trans(2);
}
//輸入,配對(duì)點(diǎn)的數(shù)量
int total = static_cast<int>(points1.size());
//輸出,旋轉(zhuǎn)矩陣
//輸出,平移向量
double mm[3][3] = { 0 }, t[3] = { 0 };
//由點(diǎn)對(duì)獲取坐標(biāo)系1變換到坐標(biāo)系2下的旋轉(zhuǎn)矩陣和平移向量
auto pairs = techlego::am::get_rt_by_pt_pairs(points2.data(), points1.data(), total, mm, t);
std::cout << "原旋轉(zhuǎn)矩陣:\n" << m << "\n";
std::cout << "原平移向量:" << translate_vector.transpose() << "\n";
std::cout << "解得的旋轉(zhuǎn)矩陣:";
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
std::cout << " " << mm[i][j] << '\t';
}
std::cout << std::endl;
}
std::cout << "解得的平移向量:";
for (int i = 0; i < 3; i++)
{
std::cout << t[i] << " ";
}
std::cout << "\n各個(gè)點(diǎn)對(duì)距離的平方和:" << pairs << std::endl;
return 0;
}